home *** CD-ROM | disk | FTP | other *** search
/ Personal Computer World 2009 February / PCWFEB09.iso / Software / Resources / Chat & Communication / Digsby build 37 / digsby_setup.exe / lib / dns / namedict.pyo (.txt) < prev    next >
Python Compiled Bytecode  |  2008-10-13  |  1KB  |  39 lines

  1. # Source Generated with Decompyle++
  2. # File: in.pyo (Python 2.5)
  3.  
  4. import dns.name as dns
  5.  
  6. class NameDict(dict):
  7.     
  8.     def __init__(self, *args, **kwargs):
  9.         super(NameDict, self).__init__(*args, **kwargs)
  10.         self.max_depth = 0
  11.  
  12.     
  13.     def __setitem__(self, key, value):
  14.         if not isinstance(key, dns.name.Name):
  15.             raise ValueError, 'NameDict key must be a name'
  16.         
  17.         depth = len(key)
  18.         if depth > self.max_depth:
  19.             self.max_depth = depth
  20.         
  21.         super(NameDict, self).__setitem__(key, value)
  22.  
  23.     
  24.     def get_deepest_match(self, name):
  25.         depth = len(name)
  26.         if depth > self.max_depth:
  27.             depth = self.max_depth
  28.         
  29.         for i in xrange(-depth, 0):
  30.             n = dns.name.Name(name[i:])
  31.             if self.has_key(n):
  32.                 return (n, self[n])
  33.                 continue
  34.         
  35.         v = self[dns.name.empty]
  36.         return (dns.name.empty, v)
  37.  
  38.  
  39.